//
//  THomeHelperListViewController.m
//  LoveShare
//
//  Created by ways on 2017/4/27.
//  Copyright © 2017年 tikeyc. All rights reserved.
//

#import "THomeHelperListViewController.h"

#import "TReleaseHomeHelperViewController.h"
#import "THomeHelperListTableView.h"

@interface THomeHelperListViewController ()

@property (strong, nonatomic) IBOutlet THomeHelperListTableView *tableView;
@property (strong, nonatomic) IBOutlet UIButton *releaseButton;

@end

@implementation THomeHelperListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    [self initProperty];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


#pragma mark - init

- (void)initProperty {
    
    if (_isReleaseHomeHelperComing) {
        self.title = @"找帮手发布记录";
    } else self.title = @"令居帮手";
    
    @weakify(self)
    [[self.releaseButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        if (self.isReleaseHomeHelperComing) {
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            TReleaseHomeHelperViewController *homeHelperVC = [[TReleaseHomeHelperViewController alloc] init];
            [self.navigationController pushViewController:homeHelperVC animated:YES];
        }
        
    }];
    
    [self initMJRefresh];
}

- (void)initMJRefresh {
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //Call this Block When enter the refresh status automatically
        [self loadNewData];
    }];
    // Enter the refresh status immediately
    [self.tableView.mj_header beginRefreshing];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //Call this Block When enter the refresh status automatically
        [self loadMoreData];
    }];
}


#pragma mark -

- (void)loadNewData {
    [self.tableView.mj_header performSelector:@selector(endRefreshing) withObject:nil afterDelay:1.0];
}

- (void)loadMoreData {
    [self.tableView.mj_footer performSelector:@selector(endRefreshing) withObject:nil afterDelay:1.0];
}


@end
